package util;

import java.util.ArrayList;
import java.util.List;

public class IntervalIndividualConverter {
	private static int from = 0;
	private static int to = 10;

	public static double indivitualToDouble(Integer individual) {

		double tmp = individual / (double) (Integer.MAX_VALUE);
		tmp = tmp * (to - from) / 2;
		tmp += (double) (to - from) / 2;

		return tmp;
	}

	public static int doubleToIndividual(double individualDouble) {

		double newInd = individualDouble - (double) (to - from) / 2;
		//System.out.println("newInd= " + newInd);
		newInd = 2 * newInd / (to - from);
		return (int)Math.ceil( (newInd * Integer.MAX_VALUE));
	}
	
	public static List<Integer> convertToInt(List<Double> list){
		
		List<Integer> result = new ArrayList<Integer>();
		
		for(Double value: list){
			result.add(doubleToIndividual(value));
		}
		return result;
	}
	
	public static List<Double> convertToDouble(List<Integer> list){

		List<Double> result = new ArrayList<Double>();

		for(Integer value: list){
			result.add(indivitualToDouble(value));
		}
		return result;
	}

//	public static void main(String[] args) {
//		//double a = 0.0;
//		double b = 5+  (double)5/Integer.MAX_VALUE;
//		System.out.println("b:"+ b);
//		//int ind = doubleToIndividual(a);
//		int ind1 = doubleToIndividual(b);
//		//System.out.println(a);
//		//System.out.println(ind);
//		//System.out.println(indivitualToDouble(ind));
//		System.out.println(indivitualToDouble(ind1));
//
//	}
}
